<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@page import="java.net.URLDecoder"%>
<%@ page import="com.sz.ticket.dao.ITicketDAO" %>
<%@ page import="com.sz.common.SZUtility" %>
<%@page import="com.sz.business.dao.IBusinessDAO"%>

<%
//复制自viewTicket.jsp,基本上没改

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";


String style1 = "width: 100px;text-align:right;font-size: 12px;";
String style2 = "font-size: 12px";

String input_text = "width: 220px";
String input_text_gray = "width: 220px; color: gray";

String title = "订单历史详情";
if(title != null) {
	title = URLDecoder.decode(title, "UTF-8");
}

//模式 	mode_edit 或  mode_confirm
String mode = request.getParameter("mode");
if(mode==null || mode.equals("")) {
	mode = "mode_edit";
}

String button_name = "";
if(mode.equals("mode_edit")) {
	button_name = "提交更改";
} else if(mode.equals("mode_confirm")) {
	button_name = "提交确认";
}

ServletContext servletContext = request.getSession().getServletContext(); 
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ITicketDAO ticket = (ITicketDAO) context.getBean("TicketDAO");
IBusinessDAO business = (IBusinessDAO) context.getBean("BusinessDAO");

String show_title = request.getParameter("show_title");
if(show_title == null || show_title.length() == 0) show_title = "1"; //默认显示

String show_confirm_title = request.getParameter("show_confirm_title"); //是否显示"确认信息"四个字
if(show_confirm_title == null || show_confirm_title.length() == 0) show_confirm_title = "1"; //默认显示

Map<Object, Object> param = new HashMap<Object, Object>();
String ticket_id = request.getParameter("TICKET_ID");
String iid = request.getParameter("iid");
param.put("IID", iid);
List list = ticket.queryTicketLog(param);
String bExist = "1";	//订单是否存在的标志
Map map = new HashMap();
if(list.size() > 0) {
	map = (Map)list.get(0);
	bExist = "1";
} else {
	bExist = "0";
}

String cust_tel = SZUtility.toString(map.get("CUST_TEL"));
String cust_name = SZUtility.toString(map.get("CUST_NAME"));
String business_id = SZUtility.toString(map.get("BUSINESS_ID"));
String demand_time_str = SZUtility.toString(map.get("DEMAND_TIME_STR"));
String demand_num = SZUtility.toString(map.get("DEMAND_NUM"));
String demand_addition = SZUtility.toString(map.get("DEMAND_ADDITION"));
String staff_num = SZUtility.toString(map.get("STAFF_NUM"));
String create_manager_name = SZUtility.toString(map.get("CREATE_MANAGER_NAME"));
String create_time_str = SZUtility.toString(map.get("CREATE_TIME_STR"));
String lock_time_str = SZUtility.toString(map.get("LOCK_TIME_STR"));
String lock_manager_name = SZUtility.toString(map.get("LOCK_MANAGER_NAME"));
String custom_change = SZUtility.toString(map.get("CUSTOM_CHANGE"));
String business_response = SZUtility.toString(map.get("BUSINESS_RESPONSE"));
String version_str = SZUtility.toString(map.get("VERSION_STR"));

String business_name = SZUtility.toString(map.get("BUSINESS_NAME"));
String business_regionname = SZUtility.toString(map.get("BUSINESS_REGIONNAME"));
String business_address = SZUtility.toString(map.get("BUSINESS_ADDRESS"));
String business_tel = SZUtility.toString(map.get("BUSINESS_TEL"));
String low_fee = SZUtility.toString(map.get("LOW_FEE"));
String landmark = SZUtility.toString(map.get("LANDMARK"));

String card_no = SZUtility.toString(map.get("CARD_NO"));
String position_flag = SZUtility.toString(map.get("POSITION_FLAG"));
String nosmoking_flag = SZUtility.toString(map.get("NOSMOKING_FLAG"));
String window_flag = SZUtility.toString(map.get("WINDOW_FLAG"));
String baby_flag = SZUtility.toString(map.get("BABY_FLAG"));
String wc_flag = SZUtility.toString(map.get("WC_FLAG"));
String notice_flag = SZUtility.toString(map.get("NOTICE_FLAG"));

String business_change = SZUtility.toString(map.get("BUSINESS_CHANGE"));
String discount_descrip = SZUtility.toString(map.get("DISCOUNT_DESCRIP"));
String need_deposit = SZUtility.toString(map.get("NEED_DEPOSIT"));
String contact = SZUtility.toString(map.get("CONTACT"));
String comment_text = SZUtility.toString(map.get("COMMENT_TEXT"));

String demand_time_d = demand_time_str.substring(0,10);
String demand_time_t = demand_time_str.substring(11,16);

String status = SZUtility.toString(map.get("STATUS"));
String status_name = SZUtility.toString(map.get("STATUS_NAME"));

String cust_sex = SZUtility.toString(map.get("CUST_SEX"));

/* 以下在mode_confirm模式使用 */
String change_from = "";
String checkbox_tip = "";
String only_notice = "0";  	//31客户取消,待通知商家 和 41商家取消,待通知客户，仅需要通知
String do_nothing = "0";	//确认完成 和 取消完成，什么都不能做
String show_confirmfailed = "0";	//是否显示确认失败按钮  仅确认模式下

if(status.equals("1") || status.equals("11")) {
	// 1 	客户下单,待商家确认
	// 11 	客户更改,待商家确认	
	change_from = "2";
	if(mode.equals("mode_confirm")) show_confirmfailed = "1";  //仅确认模式下可见
	checkbox_tip = "若商家需要对订单做细微的调整，请点击这里";
} else if(status.equals("21")) {	
	// 21 	商家更改,待客户确认
	change_from = "1";
	if(mode.equals("mode_confirm")) show_confirmfailed = "1"; //仅确认模式下可见
	checkbox_tip = "若客户需要对订单做细微的调整，请点击这里";
} else if(status.equals("31") || status.equals("41") || status.equals("22") || status.equals("2") || status.equals("12") ||
		status.equals("51") || status.equals("52")) {
	// 31	客户取消,待通知商家
	// 41	商家取消,待通知客户
	// 22	客户已确认(更改),待通知商家
	// 2	商家已确认,待通知客户
	// 12	商家已确认(更改),待通知客户
	// 51	商家确认失败，待通知客户
	// 52	客户确认失败，待通知商家
	only_notice = "1";
} else if(status.equals("81") || status.equals("82") || status.equals("99") || status.equals("83")) {
	// 81	客户取消完成
	// 82	商家取消完成
	// 99	确认完成
	// 83	订单确认失败，已取消
	do_nothing = "1";
}

%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link href="<%= request.getContextPath() %>/css/main.css" rel="stylesheet" type="text/css" />
		<base href="<%=basePath%>" target="_self">
		<title><%=title%></title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="">
		<meta http-equiv="description" content="订单历史详情" >
	</head>
	
	<body onload="onLoad()">
		<script type="text/javascript" src="js/calendar.js"></script>
		<script type="text/javascript" src="js/utility.js"></script>
		
		<% if(show_title.equals("0") == false) { %> 
		<table width="100%">
		  <tr>
		  	<td colspan="3" class="title0" ><%=title%></td>		  	
	  	  </tr>
	  	</table> 
		<% } %>
		
	  	<table id = "business_info" width="100%" border="0" cellpadding="0" cellspacing="0" style="line-height:30px;">
	  		<tr>
	  			<th colspan="6" align="left">商家信息</th>
	  		</tr>
	  		<tr>
	  			<td style="<%=style1%>">商家名称&nbsp</td>
	  			<td>
	  				<input type="text" id="business_name" name="business_name" value="<%=business_name%>"  readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">区域&nbsp</td>
	  			<td>
	  				<input type="text" id="business_regionname" name="business_regionname" value="<%=business_regionname%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">地址&nbsp</td>
	  			<td>
	  				<input type="text" id="business_address" name="business_address" value="<%=business_address%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  		</tr>
	  		
	  		<tr>
	  			<td style="<%=style1%>">预订电话&nbsp</td>
	  			<td>
	  				<input type="text" id="business_tel" name="business_tel" value="<%=business_tel%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">最低消费&nbsp</td>
	  			<td>
	  				<input type="text" id="low_fee" name="low_fee" value="<%=low_fee%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  			
	  			<td style="<%=style1%>">地标&nbsp</td>
	  			<td>
	  				<input type="text" id="landmark" name="landmark" value="<%=landmark%>" readonly="readonly" style="<%=input_text_gray%>" >
	  			</td>
	  		</tr>	  		
	  	</table>	  	

	  	 <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" style="line-height:30px;">
	  	 	<tr>
	  			<th colspan="6" align="left">订单信息</th>
	  		</tr>		  	
  		<tr>
		  	<td style="<%=style1%>">客户电话&nbsp</td>
		  	<td>
		  		<input type="text" id="cust_tel" name="cust_tel" value="<%=cust_tel%>" readonly="readonly" style="<%=input_text_gray%>" >
		  	</td>
		  	
		  	<td style="<%=style1%>">客户姓名&nbsp</td>
		  	<td>
		  		<input type="text" id="cust_name" name="cust_name" value="<%=cust_name%>" readonly="readonly" style="<%=input_text_gray%>" >
		  	</td>
		  	
		  	<td style="<%=style1%>">客户性别</td>
		  	<td style="font-size: 12px;">
		  		&nbsp;<input type="radio" id="sex_male" onclick="onClickRadio_sex('sex_male')" disabled="disabled">男
		  		<input type="radio" id="sex_female" onclick="onClickRadio_sex('sex_female')" disabled="disabled">女
		  		<input type="radio" id="sex_unknown" onclick="onClickRadio_sex('sex_unknown')" disabled="disabled">未知
		  	</td>		  				 
	  	</tr>
  		  	
	  	<tr>
	  		<td style="<%=style1%>">预约时间&nbsp</td>
		  	<td>
		  		<input type="text" id="demand_time_d" name="demand_time_d" style="width: 95px;" value="<%=demand_time_d%>" readonly="readonly" onclick="calendar.show(this)" >
		  		<select id="demand_time_t" name="demand_time_t" style="width: 80px;" >
		  		  <option selected="selected"></option>
		  		  <%
		  		  String value;
		  		  String text;
		  		  
		  		  String value_half;
		  		  String text_half;
		  		  boolean b = false;
		  		  boolean b_half = false;
				  for(int n = 0; n < 24; ++n) {
				   	  String t = String.format("%02d", n);				  
					  value = t + ":" + "00";
					  text = t + "时";
					  
					  value_half = t + ":" + "30";
					  text_half = " " + t + "时" + "30分";
					  					  
					 
					  b = value.equals(demand_time_t);
					  b_half = value_half.equals(demand_time_t);					  					
					 
				  %>
				   <option <%if(b){%> selected="selected" <%}%>
				     value="<%=value%>"><%=text%>
				   </option>
				   <option <%if(b_half){%> selected="selected" <%}%>
				     value="<%=value_half%>"><%=text_half%>
				   </option>
				  <%}%>				   
		  		</select>
		  	</td>
		  		
		  	<td style="<%=style1%>">预约桌数&nbsp</td>
		  	<td>
		  		<input type="text"  id="demand_num" name="demand_num"  value="<%=demand_num%>" style="<%=input_text%>">
		  	</td>
		  	
		  	<td style="<%=style1%>">用餐人数&nbsp</td>
		  	<td>
		  		<input type="text" id="staff_num" name="staff_num" value="<%=staff_num%>" style="<%=input_text%>">
		  	</td>	  
	  	</tr>

	  	<tr>
	  		<td style="<%=style1%>">用餐环境&nbsp</td>
	  		<td style="<%=style2%>">
		  		<input type="radio" id="position_room" onclick="onClickRadio_position('position_room')">包厢
		  		<input type="radio" id="position_mall" onclick="onClickRadio_position('position_mall')">大厅
		  		<input type="radio" id="position_any" onclick="onClickRadio_position('position_any')">不限		  		
		  	</td>
	  		<td style="<%=style1%>">预订要求&nbsp</td>
	  		<td style="<%=style2%>">
		  		<input type="checkbox" id="window" name="window" />靠窗 
		  		<input type="checkbox" id="nosmoking" name="nosmoking" />无烟区
		  		<input type="checkbox" id="baby" name="baby" />宝宝椅
		  		<input type="checkbox" id=wc name="wc" />卫生间	  		
		  	</td>
		  	<td style="<%=style1%>">商旅卡号&nbsp</td>
		  	<td>
		  		<input type="text" id="card_no" name="card_no" value="<%=card_no%>" readonly="readonly" style="<%=input_text_gray%>" >
		  	</td>  
		  	<!--  
		  	<td style="<%=style1%>">确认方式&nbsp</td>
	  		<td>
		  		<input type="checkbox" id="notice_phone" />电话 
		  		<input type="checkbox" id="notice_sms" />短信		
		  	</td>
		  	-->		  	
	  	</tr>
	  	<tr>
	  		<td style="<%=style1%>">下单人&nbsp</td>
	  		<td>
				<input type="text" id="create_manager_name" name="create_manager_name" value="<%=create_manager_name%>" readonly="readonly" style="<%=input_text_gray%>">
		  	</td>
		  	
		  	<td style="<%=style1%>">下单时间&nbsp</td>
	  		<td>
				<input type="text" id="create_time_str" name="create_time_str" value="<%=create_time_str%>" readonly="readonly" style="<%=input_text_gray%>">
		  	</td>
		  	
		  	<td style="<%=style1%>">订单编号&nbsp</td>
		  	<td>
		  		<input type="text" id="ticket_id" name="ticket_id" value="<%=ticket_id%>" readonly="readonly" style="<%=input_text_gray%>" >
		  	</td>		  	
	  	</tr>
	  	<tr>
	  		<td style="<%=style1%>">附加要求&nbsp</td>
		  	<td colspan="1">
		  		<textarea id="demand_addition" name="demand_addition" style="<%=input_text%>; height:80px" ><%=demand_addition%></textarea>
		  	</td>
		  	<!--  		  	
		  	<td style="<%=style1%>">客户更改&nbsp</td>
		  	<td colspan="1">
		  		<textarea rows="" cols="" id="custom_change" name="custom_change" readonly="readonly" style="<%=input_text_gray%>; height:80px"><%=custom_change%></textarea>
		  	</td>
		  	-->
		  	
		  	<td style="<%=style1%>">商家更改&nbsp</td>
		  	<td>
		  		<input type="text" id="business_change" name="business_change" value="<%=business_change%>" readonly="readonly" style="<%=input_text_gray%>; height:80px">
		  	</td>	

	  	</tr>
	  	</table>	  	

  	
  	<table id="confirm_info" width="100%" border="0" cellpadding="0" cellspacing="0" style="line-height:30px;">
  		<% if(show_confirm_title.equals("0") == false) { %> 
  		<tr>
  			<th colspan="6" align="left">确认信息</th>  		
  		</tr>
  		<% } %>
  		<tr>
  			<td style="<%=style1%>">预订结果</td>
  			<td>
  				<input type="text" id="business_response" name="business_response" value="<%=business_response%>" style="<%=input_text%>" >
   			</td>
   			
   			<td style="<%=style1%>">折扣说明</td>
   			<td>
   				<input type="text" id="discount_descrip" name="discount_descrip" value="<%=discount_descrip%>" readonly="readonly" style="<%=input_text_gray%>" >
   			</td>
   			
   			<td style="<%=style1%>">备注</td>
   			<td>
   				<input type="text" id="comment_text" name="comment_text" value="<%=comment_text%>" readonly="readonly" style="<%=input_text_gray%>" >
   			</td>
  		</tr>
  		
  		<tr>
  			<td style="<%=style1%>">商家联系人</td>
  			 <td>
   				<input type="text" id="contact" name="contact" value="<%=contact%>" readonly="readonly" style="<%=input_text_gray%>" >
   			</td>
   			
   			<td style="<%=style1%>">要定金</td>
   			<td>
   				<input type="checkbox" id="check_deposit" />			
   			</td>
  		</tr>
  	
  	</table> 
  	  		
  	<form id="submitForm" method="post" action="ticket/editTicket.exec" style="display: none;">
  		<input id="OPERATE_TYPE" name="OPERATE_TYPE" value="" />
  		<input id="PARAM" name="PARAM" value="" />
  	</form>
  	
  	<SCRIPT LANGUAGE="JavaScript">
  	
  		function onLoad() {
  			resetControls();
  			if("<%=bExist%>" == "0") {
  				alert("根据查到指定的订单");
  			}
  		}
  		function onClickRadio(value) {
  			if(value == "1") { //客户
  				document.getElementById("radio_custom_change").checked = true;
  				document.getElementById("radio_business_change").checked = false;
  				
  				resetControls();
  				customControls();
  			} else if(value == "2") { // 商家
  				document.getElementById("radio_business_change").checked = true;
  				document.getElementById("radio_custom_change").checked = false;
  				
  				resetControls();
  				businessContorls();
  			}
  		}
  		function onClickCheckbox(value) {
  		  	if("<%=do_nothing%>" == "1") {
  		  		document.getElementById("checkbox").checked = false;
  				alert("订单当前的状态为:" + "<%=status_name%>" + "，不能再进行更改");
  				return;
  	  		}
  	  		if("<%=only_notice%>" == "1") {
  	  			document.getElementById("checkbox").checked = false;
  				alert("订单当前的状态为:" + "<%=status_name%>" + "，不能再进行更改");
  				return;
  	  		}  	  			
  		  	if(value == "1") { //客户  				
  				resetControls();
  				customControls();
  			} else if(value == "2") { // 商家  				
  				resetControls();
  				businessContorls();
  			}	
  		}
  		function resetControls() {
  			
  			document.getElementById("demand_time_d").disabled = true;
 			document.getElementById("demand_time_t").disabled = true;
 			
  			document.getElementById("demand_num").readOnly = true;
  			document.getElementById("demand_addition").readOnly = true;
  			document.getElementById("staff_num").readOnly = true;
  			document.getElementById("business_change").readOnly = true;
  			  			
  			document.getElementById("demand_num").style.color = "gray";
  			document.getElementById("demand_addition").style.color = "gray";
  			document.getElementById("staff_num").style.color = "gray";
  			document.getElementById("business_change").style.color = "gray";  			
  			
  			if("<%=position_flag%>" == "0") {  			
  				document.getElementById("position_any").checked = true;
  			} else if("<%=position_flag%>" == "1") {
  				document.getElementById("position_mall").checked = true;
  			} else if("<%=position_flag%>" == "2") {
  				document.getElementById("position_room").checked = true;
  			}
  			document.getElementById("position_any").disabled = true;
  			document.getElementById("position_mall").disabled = true;
  			document.getElementById("position_room").disabled = true;	
  			
  			if("<%=window_flag%>" == "1") {
  				document.getElementById("window").checked = true;
  			}
  			if("<%=nosmoking_flag%>" == "1") {
  				document.getElementById("nosmoking").checked = true;
  			}
  			if("<%=baby_flag%>" == "1") {
  				document.getElementById("baby").checked = true;
  			}
  			if("<%=wc_flag%>" == "1") {
  				document.getElementById("wc").checked = true;
  			}
  			document.getElementById("window").disabled = true;
  			document.getElementById("nosmoking").disabled = true;
  			document.getElementById("baby").disabled = true;
  			document.getElementById("wc").disabled = true;
  			
  			/* //去掉确认方式
  			if("<%=notice_flag%>" == "1") {
  				document.getElementById("notice_phone").checked = true;
  			} else if("<%=notice_flag%>" == "2") {
  				document.getElementById("notice_sms").checked = true;
  			} else if("<%=notice_flag%>" == "3") {
  				document.getElementById("notice_phone").checked = true;
  				document.getElementById("notice_sms").checked = true;
  			}
  			document.getElementById("notice_phone").disabled = true;
  			document.getElementById("notice_sms").disabled = true;
  			*/

			if("<%=need_deposit%>" == "1") {
				document.getElementById("check_deposit").checked = true;
			}
			document.getElementById("check_deposit").disabled = true;
			
			var sex = "<%=cust_sex%>";
			if(sex == "1") {
				document.getElementById("sex_male").checked = true
			} else if(sex == "0") {
				document.getElementById("sex_female").checked = true
			} else {
				document.getElementById("sex_unknown").checked = true
			}
  		}
  		
  		function customControls() {
  		  	document.getElementById("demand_time_d").disabled = false;
  			document.getElementById("demand_time_t").disabled = false;
  			
  			document.getElementById("demand_num").readOnly = false;
  			document.getElementById("demand_addition").readOnly = false;
  			document.getElementById("staff_num").readOnly = false;
  			
  			document.getElementById("demand_num").style.color = "black";
  			document.getElementById("demand_addition").style.color = "black";
  			document.getElementById("staff_num").style.color = "black";
  			
  			document.getElementById("position_any").disabled = false;
  			document.getElementById("position_mall").disabled = false;
  			document.getElementById("position_room").disabled = false;	
  			
  			document.getElementById("window").disabled = false;
  			document.getElementById("nosmoking").disabled = false;
  			document.getElementById("baby").disabled = false;
  			document.getElementById("wc").disabled = false;
  		}
  		function businessContorls() {
  			document.getElementById("business_change").readOnly = false;
  			document.getElementById("business_change").style.color = "black";  				
  		}
  		
  		function onSubmit() {
  		  	
  		  	if("<%=mode%>" == "mode_edit") {
	  		  	var from = 0;  		
	  	  		if(document.getElementById("radio_custom_change").checked == true) from = 1;
	  	  		else if(document.getElementById("radio_business_change").checked == true) from = 2;
	  	  		else { alert("订单未做更改"); return; }
	  	  		
	  	  		if(from == 1) {
	  	  			onCustomChange();
	  	  		} else if(from == 2) {
	  	  			onBusinessChange();
	  	  		}
  	  		} else if("<%=mode%>" == "mode_confirm") {
  	  			if("<%=do_nothing%>" == "1") {
  	  				alert("订单当前的状态为:" + "<%=status_name%>" + "，无需再确认");
  	  				return;
  	  			}
  	  			
  	  			if(document.getElementById("checkbox_change").checked == true) {
  	  				if("<%=change_from%>" == "1") {
  	  					onCustomChange();
  	  				} else if("<%=change_from%>" == "2") {
  	  					onBusinessChange();
  	  				} 
  	  			} else {
  	  				//审核无更改
  	  				onNextStatus();
  	  			}
  	  		} 
  			
  		}
  		
  		function formatChangeTitle(title) {
  			return "[" + title + "]  ";
  		}
  		
  		function onCustomChange() {
   			var custom_change = "";
  			var flag = "更改为："
 			var nessesary = 0;
 			var optional = 0;

  			//预约时间
  			var new_demand_time = document.getElementById("demand_time_d").value;
  			if(IsEmpty(new_demand_time)==true) {
  	  			alert("请预约时间");
  	  			return null;
  			}  			 			
  			
  			var temp = document.getElementById("demand_time_t").value;
  			if(IsEmpty(temp)==true) {
  	  			alert("请预约时间");
  	  			return null;
  			}
  			new_demand_time += " ";
  			new_demand_time += temp;  			
  			if(new_demand_time != "<%=demand_time_str%>") {
  				custom_change += formatChangeTitle("预约时间");
  				custom_change += "<%=demand_time_str%>"; custom_change += "时"
  				custom_change += flag;
  				custom_change += new_demand_time; custom_change += "时"
  				custom_change += "\n";
  				
  				nessesary++;
  			}
  			
  			//预约桌数
  			var new_demand_num = document.getElementById("demand_num").value;
  			if(IsInteger(new_demand_num)==false) {
  	  			alert("请正确数据预约桌数，只能为数字");
  	  			return null;
  			}
  			if(new_demand_num != "<%=demand_num%>") {
  				custom_change += formatChangeTitle("预约桌数");
  				custom_change += "<%=demand_num%>";
  				custom_change += flag;
  				custom_change += new_demand_num;
  				custom_change += "\n";
  				
  				nessesary++;
  			}
  			
  			//用餐人数
  			var new_staff_num = document.getElementById("staff_num").value;
  			if(IsInteger(new_staff_num)==false) {
  	  			alert("请正确填写用餐人数");
  	  			return null;
  			}
  			if(new_staff_num != "<%=staff_num%>") {
  				custom_change += formatChangeTitle("用餐人数");
  				custom_change += "<%=staff_num%>";
  				custom_change += flag;
  				custom_change += new_staff_num;
  				custom_change += "\n";
  				  				
  				nessesary++;
  			}
  			
  			//附加条件
  			/* 去掉
  			var new_demand_addition = document.getElementById("demand_addition").value;
  			if(new_demand_addition != "<%=demand_addition%>") {
  				custom_change += formatChangeTitle("附加要求");
  				custom_change += "<%=demand_addition%>";
  				custom_change += flag;
  				custom_change += new_demand_addition;
  				custom_change += "\n";
  				
  				nessesary++;
  			}
  			*/
  			
  			if(nessesary == 0) {  				
  				alert("订单未发生实质更改");  				
  				return;
  			}
  			
  			var param = "{TICKET_ID:";
  			param += "'"+"<%=ticket_id%>"+"',";
  			param += "CHANGE_FROM:";
  			param += "'1',";
  			param += "MYVERSION:";
  			param += "'"+"<%=version_str%>"+"',";
  			param += "DEMAND_TIME:";
  			param += "'"+new_demand_time+"',";
  			param += "DEMAND_NUM:";
  			param += "'"+new_demand_num+"',";
  			param += "DEMAND_ADDITION:";
  			param += "'"+new_demand_addition+"',";
  			param += "STAFF_NUM:";
  			param += "'"+new_staff_num+"',";
  			param += "CUSTOM_CHANGE:";
  			param += "'"+custom_change+"'";
  			
  			param += "}";
  			
  			//提交
  			document.getElementById("OPERATE_TYPE").value = "EDIT";
  			document.getElementById("PARAM").value = param;
  			document.getElementById("submitForm").submit();
  			
  			
  	  		//在网页对话框中ajax有问题 	  			
//			$.ajax({
//				type: "POST",
//				url: "ticket/editTicket.ajax",
//				data: {OPERATE_TYPE:"EDIT", PARAM:param},
//				datatype:"json",
//				success: editSuccess,
//				error: show_error
//  	  		});
  		}
  		function onBusinessChange() {   			
			var nessesary = 0;
  			var new_business_change = document.getElementById("business_change").value;
  			if(new_business_change != "<%=business_change%>") {
  				nessesary++;
  			}
  			
  			if(nessesary == 0) {
  				alert("订单未发生更改");  				
  				return;
  			}
  			
  			var param = "{TICKET_ID:";
  			param += "'"+"<%=ticket_id%>"+"',";
  			param += "CHANGE_FROM:";
  			param += "'2',";
  			param += "MYVERSION:";
  			param += "'"+"<%=version_str%>"+"',";
  			param += "BUSINESS_CHANGE:";
  			param += "'"+new_business_change+"'";  			
  			param += "}";
  			
  			//提交
  			document.getElementById("OPERATE_TYPE").value = "EDIT";
  			document.getElementById("PARAM").value = param;
  			document.getElementById("submitForm").submit();
  			
  			
  	  		//在网页对话框中ajax有问题 	  			
//			$.ajax({
//				type: "POST",
//				url: "ticket/editTicket.ajax",
//				data: {OPERATE_TYPE:"EDIT", PARAM:param},
//				datatype:"json",
//				success: editSuccess,
//				error: show_error
//  	  		});
  		}
  		function editSuccess(data) {
  			alert(data);
  			window.close();
  		}
 		function showMsg(data) {
  	  		alert(data);
 		}
  	
  		function onNextStatus() {
  			if("<%=mode%>" != "mode_confirm") {
  				alert("该调用仅在审核模式下使用");
  				return;
  			}
  			if(document.getElementById("checkbox_change").checked == true) {
  				alert("订单发生了更改，不能进行该调用");
  				return;
  			}
  			
  			var tmp = "0";
  			if(document.getElementById("check_deposit").checked == true) {
  				tmp = "1";
  			}
  			
  	  		var param = "{TICKET_ID:";
  			param += "'"+"<%=ticket_id%>"+"',";
  			param += "BUSINESS_RESPONSE:";
  			param += "'"+document.getElementById("business_response").value+"',";
  			param += "DISCOUNT_DESCRIP:";
  			param += "'"+document.getElementById("discount_descrip").value+"',";
  			param += "COMMENT_TEXT:";
  			param += "'"+document.getElementById("comment_text").value+"',";
  			param += "CONTACT:";
  			param += "'"+document.getElementById("contact").value+"',";
  			param += "NEED_DEPOSIT:";
  			param += "'"+tmp+"',";  			
  			param += "MYVERSION:";
  			param += "'"+"<%=version_str%>"+"'";		
  			param += "}";
  			
  			//提交
  			document.getElementById("OPERATE_TYPE").value = "NEXTSTATUS";
  			document.getElementById("PARAM").value = param;
  			document.getElementById("submitForm").submit();		
  		}
  		function onCancelTicket() {
  			//目前使用change_from撤单发起方
  			if("<%=mode%>" == "mode_confirm") { //仅审核模式
  				//var tip = "确认是";
  				//if("<%=change_from%>" == "1") {
  				//	tip += "客户";
  				//} else if("<%=change_from%>" == "2") {
  				//	tip += "商家";
  				//} else {
  				//	return; 
  				//}
  				//tip += "撤单吗？"
  				//if(window.confirm(tip) == false) return;
  				
	  			var param = "{TICKET_ID:";
	  			param += "'"+"<%=ticket_id%>"+"',";
	  			param += "FAILED_FROM:";
	  			param += "'"+"<%=change_from%>"+"',";
	  			param += "MYVERSION:";
	  			param += "'"+"<%=version_str%>"+"',";	  			
	  			param += "}"; 
	  			
	  			document.getElementById("OPERATE_TYPE").value = "CONFIRMFAILED";
	  			document.getElementById("PARAM").value = param;
	  			document.getElementById("submitForm").submit();		 				
  	  		} //end if			
  		}
  		
  		function onClickRadio_sex(id) {
  			if(id == 'sex_male') {
 				document.getElementById("sex_male").checked = true;
 				document.getElementById("sex_female").checked = false;
 				document.getElementById("sex_unknown").checked = false;
 			} else if(id == 'sex_female'){
 				document.getElementById("sex_female").checked = true;
 				document.getElementById("sex_male").checked = false; 				
 				document.getElementById("sex_unknown").checked = false;
 			} else {
 				document.getElementById("sex_unknown").checked = true;
 				document.getElementById("sex_female").checked = false;
 				document.getElementById("sex_male").checked = false; 				
 				
 			}
  		}
  	</SCRIPT>
	</body>
</html>
